import os
import pathlib
import sys

root_path = str(pathlib.Path(os.path.abspath(__file__)).parent.parent)
sys.path.append(root_path)

from sklearn.model_selection import GridSearchCV
from ml_utils.config.base_config import *


def grid_search_cls(x, y, model, params):
    grid = GridSearchCV(model, params, cv=5, verbose=verbose, scoring='f1_micro', n_jobs=n_jobs)
    print()
    print('*' * 100)
    print('grid search begin')
    res = grid.fit(x, y)
    print('best f1_micro:', res.best_score_)
    print('best param:', res.best_params_)
    return res.best_params_


def grid_search_reg(x, y, model, params):
    grid = GridSearchCV(model, params, cv=5, verbose=verbose, scoring='neg_mean_squared_error', iid=True, n_jobs=n_jobs)
    print()
    print('*' * 100)
    print('grid search begin')
    res = grid.fit(x, y)
    print('best loss:', res.best_score_)
    print('best param:', res.best_params_)
    return res.best_params_


def grid_search_cluster(x, model, params):
    grid = GridSearchCV(model, params, cv=5, verbose=verbose, iid=True, n_jobs=n_jobs)
    print()
    print('*' * 100)
    print('grid search begin')
    res = grid.fit(x)
    print('best loss:', res.best_score_)
    print('best param:', res.best_params_)
    return res.best_params_
